package com.example.housingRentalSystem.service.Impl;

import com.example.housingRentalSystem.bean.Role;
import com.example.housingRentalSystem.mapper.RoleMapper;
import com.example.housingRentalSystem.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private UserServiceImpl userService;

    @Override
    public Role findByName(String name) {
        return roleMapper.findByName(name);
    }

    @Override
    public Role findById(Integer id) {
        return roleMapper.findById(id);
    }

    @Override
    public void save(Role role) {
        roleMapper.insert(role);
    }

    @Override
    public void addRoleToUser(String username, String roleName) {
        userService.addRoleToUser(username, roleName);
    }
}